package day4;

/**
 * @author joker
 * @date 2022/4/14 0014 - 17:13
 */
public class Window1 implements Runnable {
    private int ticket=100;
    @Override
    public void run() {
        sale();
    }

    private  void sale() {
        while(true){
            synchronized(this) {

                if (ticket > 0) {

                    System.out.println(Thread.currentThread().getName() + ":卖票，票号为：" + ticket);
                    ticket--;
                    try {
                        Thread.sleep(1);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                } else {
                    break;
                }
            }
        }
    }
}
